package fragment;

import android.graphics.Canvas;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.projectmoudle_two.R;

import java.util.ArrayList;
import java.util.List;

import adapter.RecycleAdapter;

/**
 * Created by eyesee on 2017/6/4.
 */

public class RecycleViewDemo extends BaseFragment {

    private View mView;
    private List<String> mList;
    private RecyclerView mRecyclerView;
    private static RecycleViewDemo mRecycleViewDemo;

    public static RecycleViewDemo getInstance(){
        if (mRecycleViewDemo==null){
            mRecycleViewDemo=new RecycleViewDemo();
        }
        return mRecycleViewDemo;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mView = View.inflate(mContext, R.layout.fragment_recycleview, null);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        prparData();
        initView(mView);
        return mView;
    }

    private void prparData() {
        mList = new ArrayList<>();
        for (int i = 0; i < 50; i++) {
            mList.add(i+"号");
        }
    }

    private void initView(View view) {
        mRecyclerView = (RecyclerView) view.findViewById(R.id.recycle);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
            @Override
            public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
                super.onDraw(c, parent, state);

            }
        });

        RecycleAdapter adapter = new RecycleAdapter(mContext,mList);
        mRecyclerView.setAdapter(adapter);
    }
}
